package style.JUC多线程与并发.Solution;

import java.util.HashMap;
import java.util.Map;

/**
 * 两数之和
 */
public class Solution {
    public static void main(String[] args) {
        int nums[] = {2,7,11,15};
        int target = 9;

        HashMap<Integer, Integer> map = new HashMap<>();
        for (int i = 0;i<nums.length ;i++) {
            map.put(i, nums[i]);
        }

        for (Map.Entry<Integer, Integer> entry : map.entrySet()){
            if (map.containsValue(target-entry.getValue())){
                System.out.println(entry.getKey());
            }
        }

        int[] returnNums = number2(nums, target);
        for (int i = 0; i < returnNums.length; i++) {
            System.out.println(returnNums[i]);
        }

    }

    private static int[] number2(int[] nums, int target) {
        HashMap<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < nums.length; i++) {
            int par = target - nums[i];
            if (map.containsKey(par)){
                return new int[]{map.get(par), i};
            }
            map.put(nums[i], i);
        }
        return null;
    }
}
